package com.zhs.gccs.view.taskMap;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhs.gccs.R;
import com.zhs.gccs.model.LocationBean;
import com.zhs.gccs.view.BaseView;
import com.zhs.gccs.utils.OnNoDoubleClickListener;

public class NavView extends BaseView {
    private View iv_close;
    private TextView tv_project;
    private TextView tv_address;
    private TextView tv_remarks;
    private View btn_nav;
    private View btn_nav_del;
    LocationBean location;

    public NavView(@NonNull Context context) {
        super(context);
    }

    public NavView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public NavView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void init(Context context, AttributeSet attrs, int defStyleAttr) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_map_nav, this, true);
//        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomerLogo);
//        String title = typedArray.getString(R.styleable.CustomerInfoItem_preText);
//        typedArray.recycle();
        iv_close = view.findViewById(R.id.iv_close);
        tv_project = view.findViewById(R.id.tv_project);
        tv_address = view.findViewById(R.id.tv_address);
        tv_remarks = view.findViewById(R.id.tv_remarks);
        btn_nav = view.findViewById(R.id.btn_nav);
        btn_nav.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (navViewListener != null) navViewListener.onNavToLocation(location,NavView.this);
            }
        });
        btn_nav_del = view.findViewById(R.id.btn_nav_del);
        btn_nav_del.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (navViewListener != null) navViewListener.deleteCurNav(location,NavView.this);
            }
        });
        iv_close.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (navViewListener != null) navViewListener.onNavClose(location,NavView.this);
            }
        });
    }

    public LocationBean getLocation() {
        return location;
    }

    public NavView setLocation(LocationBean location) {
        this.location = location;
        this.tv_address.setText(location.getAddress());
        this.tv_remarks.setText(location.getRemarks());
        return this;
    }

    public void setNavViewListener(NavViewListener navViewListener) {
        this.navViewListener = navViewListener;
    }

    private NavViewListener navViewListener;

    public interface NavViewListener {
        void onNavToLocation( LocationBean location,NavView navView);

        void onNavClose(LocationBean location, NavView navView);

        void deleteCurNav(LocationBean location, NavView navView);
    }
}
